<?php

class new_Model extends GlobalModel {
	public function newDiscussion ($data=array()) {
		$name = mysql_real_escape_string($data['name']);
		$text = mysql_real_escape_string($data['text']);
		$theme = 'Общая';
		$author = 'RiderSx';
		$time = time();
		$status = '1';
		
		$sql = "INSERT INTO `xine_discussions` SET
			`name`='$name',
			`author`='$author',
			`start_time`='$time',
			`last_reply_by`='$author',
			`last_reply_time`='$time',
			`status`='1',
			`active`='1',
			`replys_count`='1'
		";
		
		if(mysql_query($sql)) {
			$did = mysql_insert_id();
			
			$sql2 = "INSERT INTO `xine_replys` SET
				`author`='$author',
				`text`='$text',
				`time`='$time',
				`discussion_id`='$did',
				`active`='1',
				`discussion_starter`='1'
			";
			
			if(mysql_query($sql2)) {
				return $did;
			} else {
				return false;
			}
		} else {
			return false;
		}
	}
}